package cn.tedu.epidemic.webapi.controller;

import cn.tedu.community.commons.pojo.returnHome.dto.ReturnHomeDTO;
import cn.tedu.community.commons.pojo.returnHome.vo.ReturnHomeVO;
import cn.tedu.community.commons.restful.JsonPage;
import cn.tedu.community.commons.restful.JsonResult;
import cn.tedu.epidemic.service.ReturnHomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@Slf4j
@RequestMapping("/returnHome")
@Api(tags = "返乡报备控制器")
public class ReturnHomeController {

    @Autowired
    private ReturnHomeService service;

    @ApiOperation("添加返乡报备")
    @PostMapping("/insert")
    public JsonResult<Void> insert(@Valid ReturnHomeDTO returnHomeDTO){
        log.debug("控制层开始处理添加返乡报备，数据是：{}",returnHomeDTO);
        service.insert(returnHomeDTO);
        return JsonResult.ok();
    }

    @ApiOperation("根据返乡报备id删除返乡报备")
    @GetMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> deleteById(@PathVariable Long id) {
        log.debug("控制层开始处理根据返乡报备id删除返乡报备！返乡报备id是：{}", id);
        service.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("根据返乡报备id更新返乡报备")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> updateInfo(@PathVariable Long id,
                                       @Valid ReturnHomeDTO returnHomeDTO){
        log.debug("开始执行根据返乡报备id更新返乡报备，数据是：{}",returnHomeDTO);
        service.updateById(id,returnHomeDTO);
        return JsonResult.ok();
    }

    @GetMapping("/{id:[0-9]+}/select")
    @ApiOperation("查询返乡报备详情")
    public JsonResult<ReturnHomeVO> getStandardById(@PathVariable Long id) {
        log.debug("控制层开始处理查询返乡报备详情，id是：{}", id);
        ReturnHomeVO returnHomeVO = service.returnStandard(id);
        return JsonResult.ok(returnHomeVO);
    }

    @GetMapping("/page/{page:[0-9]+}/{pageSize:[0-9]+}")
    @ApiOperation("根据userID分页查询分页返乡报备列表")
    public JsonResult<JsonPage<ReturnHomeVO>> returnListPage(@PathVariable Integer page,
                                                           @PathVariable Integer pageSize){
        log.debug("控制层开始处理根据userID分页查询分页返乡报备列表，page是：{}，pageSize是：{}",page,pageSize);
        JsonPage<ReturnHomeVO> returnHomeVOJsonPage = service.returnListByUserId(page, pageSize);
        log.debug("根据userID分页查询分页返乡报备列表，数据是：{}",returnHomeVOJsonPage);
        return JsonResult.ok(returnHomeVOJsonPage);
    }

}
